<?xml version="1.0" encoding="UTF-8"?>
<html>
    <head>
        <link type="text/css" rel="stylesheet" href="./css/template.css" />
        <link type="text/css" rel="stylesheet" href="./css/SyntaxHighlighter.css" />
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>JMX and JConsole</title>
        <script language="javascript" src="./js/shInit.js" />
        <script language="javascript" src="./js/shCore.js" />
        <script language="javascript" src="./js/shBrushCpp.js" />
        <script language="javascript" src="./js/shBrushCSharp.js" />
        <script language="javascript" src="./js/shBrushCss.js" />
        <script language="javascript" src="./js/shBrushDelphi.js" />
        <script language="javascript" src="./js/shBrushJava.js" />
        <script language="javascript" src="./js/shBrushJScript.js" />
        <script language="javascript" src="./js/shBrushPhp.js" />
        <script language="javascript" src="./js/shBrushPython.js" />
        <script language="javascript" src="./js/shBrushRuby.js" />
        <script language="javascript" src="./js/shBrushSql.js" />
        <script language="javascript" src="./js/shBrushVb.js" />
        <script language="javascript" src="./js/shBrushXml.js" />
        <meta name="keywords" content="jmx,jconsole,Java,R&eacute;seau,jmx,et,jconsole,articles,4,4,certification,sun,java,solaris,articles,essentiels,tips,astuces,codes,exemple,tutorial,developpement,jsp,servlet,jdbc,jdo,j2se,j2ee,laboratoire" />
        <author>Gilles DE MATOS</author>
    </head>
    <body>
        <div class="chapter">
            <h2>Introduction</h2>
            <p>Java Management eXtension (JMX) is an API that allows to administrate Java applications and which is established as the same model as the SNMP protocol, allowing remote administration for applications. The evolution of those Java software bring their environment dynamic and unpredictable. So it is less and less obvious to mahage those applications with static solutions. So the JMX specification appears in the Java environment programming in order that every Java component can be managed, remotely or not, dynamically.</p>
            <p>Thus the JMX API allows to manage the work of running Java applications. This API is integrated in the JDK since the version 1.5.0 and offer a method in order to improve Java objects, with management operations and attributes, dynamically. This method, called "orchestration", allows the developers to invest themselves on their software without using a management API.</p>
            <br />
            <div class="subChapter">
                <h3>Orchestration</h3>
                <p>Resources' orchestration is done with Java componants called "MBean" (Manageable Bean). Those MBeans allow to read and modify Java's software configuration dynamically. That is they can stop, restart, add or even revoke a Java componant from a running application. They also allow to notify events in implementing the ModificationBroadcaster interface, generate statistics about it's running and finally to make them available. Those MBeans are able to locate malfunctions which can appear during configuration's manipulations.</p>
            </div>
            <br />
            <div class="subChapter">
                <h3>Levels</h3>
                <p>JMX can be divided in three levels :</p>
                <p />
                <ul>
                    <li>The Orchestration level : the MBeans</li>
                </ul>
				The MBeans are communication interfaces with the software managed through JMX. They are Java classes similar to the JavaBeans. So they are classes for which some properties can be viewed remotely with specified interface.
                <p>Several types of MBeans exists. The standard MBean provide properties during the working of a Java software and have an interface statically determined whereas the dynamic MBeans - available in implementing the DynamicMBean interface - have evolutive properties during the running of an application.
These one allow to display their attributes and opérations dynamically.</p>
                <p />
                <ul>
                    <li>The Server level : the MBeanServer</li>
                </ul>
				The MBean allows to manage the MBeans, it examines their states then execute operations on them. It also allows to provide adapters and protocols allowing to access to this resource from customers, such as HTML.
                <p />
                <ul>
                    <li>The Distribution level</li>
                </ul>
				It allows to interface with the MBeanServer through a remote shell. So it is protocols' connectors allowing the MBeans to communicate with a given protocol (HTMP, HTTP, SNMP, etc.). By default, an HTML connection is like we have an access to the administration of an application from an internet browser. The shell JMX JConsole allows to connect at the distribution's services. This monitoring tool allows to provide information, through a graphic shell, about perfomances and resources consumption of Java software, running on JVM. JConsole is a tool provided with the JDK 1.5.0.
            </div>
        </div>
        <div class="chapter">
            <h2>Using JConsole</h2>
            <p>Start your Java application with adding the following command com.sun.management.jmxremote :</p>
            <ul>
                <li>
                    <i>java –Dcom.sun.management.jmxremote -jar hello.jar</i>
                </li>
            </ul>
            <img src="./images/Article JMX_html_m71904c2e.jpg" />
            <br clear="left" />
            <br />
            <p>
				Then start JConsole. It is in the \bin folder of your JDK. At first, you have to connect locally or remotely with the Connect to Agent window. When you are connected, the JConsole report the running Java applications. Select your application in order to display the information about it.
                <img src="./images/Connection.jpg" />
                <br clear="left" />
            </p>
            <br />
            <p>
				The Monitoring and Management Console showed up on the tab Overview, which is the summary for JConsole and gather information about running processes and the physical memeory used, the processor and also the running classes.
                <img src="./images/Overview.jpg" />
                <br clear="left" />
            </p>
            <br />
            <p>The memory tab provides information about physical memory used. The chart informs us about the memory used by the virtual machine. It provide different views which inform us about the memory pools used by the JVM :</p>
            <ul>
                <li>End Space : the pool that the memory is initially zallocate for objects.</li>
                <li>Survivor Space : the pool that which contains the objects out of the Eden Space.</li>
                <li>Tenured Generation : the pool which contains ephemeral objects of the Survivor Space pool.</li>
                <li>Permanent Generation : the pool which contains all data concerning the Virtual Machine.</li>
                <li>Code Cache : the pool which contains the memory used for the compilation and the storage of source code.</li>
            </ul>
            <img src="./images/Memory.jpg" />
            <br clear="left" />
            <p>The diagram on the right informs us on the used memory in the different pools. This one becomes red when the used memory runs over the treshold of the use of the total memory. You can define the memory's treshold with the attribute MemoryMXBean.</p>
            <br />
            <p>The Threads tab provides informations about running processes. The left list shows the active processes. The Filter field allows to restrict this list to the desired processes. It works like a filter on the active processes. This fiels is case sensitive.</p>
            <p>
				To display information about a thread, just click on it's name in the list. The chart shows the number of active processes and their running time. The red curve is for the maximum number of child processes and the blue one for the number of active processes.
                <img src="./images/Threads.jpg" />
                <br clear="left" />
            </p>
            <br />
            <p>
				The Classes tab contains information about working classes. The chart indicates the number of running classes. The red curve informs us about the number of working classes included which ones which are waiting, the blue one about the current number of running classes. The details Section shows the number of class loaded since the launch of the Virtual Machine and also about the current number of running classes.
                <img src="./images/Classes.jpg" />
                <br clear="left" />
            </p>
            <br />
            <p>The VM Summary tab provides information anout the Virtual Machine such as the VM's version, the elapsed time since it's launch (Uptime), the arguments added to the programm during it's launch (VM arguments), the jars associated to the programm (Class path), the libraries also associated to the application (Library path).</p>
            <p>
				The VM Summary tab provides information about the compilator, such as the Total Compile Time. It also provides information about your system such as the operating system you use, the number of processors, the Process CPU time, the Total / Free physical memory.
                <img src="./images/VM Summary.jpg" />
                <br clear="left" />
            </p>
            <br />
            <p>
				The MBeans tab displays information about MBeans recorded in the MBeanServer. The left tree informs us on all MBeans. They are organized according the objects they implements. To display attributes, operations, notifications or information about a MBean, select the MBean in the list. If a attribute is alterable, you can define it's value.
                <img src="./images/MBeans_Operations.jpg" />
                <br clear="left" />
                <img src="./images/MBeans_Attributes.jpg" />
                <br clear="left" />
            </p>
        </div>
        <div class="chapter">
            
            <p>For more information about the JMX API and the monitoring tool JConsole, go to :</p>
            <ul>
                <li>
                    <a href="http://java.sun.com/j2se/1.5.0/docs/guide/jmx/spec.html" target="_blank">SUN's documentation about JMX</a>.
                </li>
                <li>
                    <a href="http://java.sun.com/j2se/1.5.0/docs/guide/jmx/tutorial/tutorialTOC.html" target="_blank">SUN's tutorial about JMX</a>.
                </li>
                <li>
                    <a href="http://java.sun.com/j2se/1.5.0/docs/guide/jmx/examples.html" target="_blank">SUN's examples about JMX</a>.
                </li>
                <li>
                    <a href="http://java.sun.com/j2se/1.5/docs/guide/management/jconsole.html" target="_blank">SUN's documentation about JConsole</a>.
                </li>
                <li>
                    <a href="http://java.sun.com/developer/technicalArticles/J2SE/jconsole.html" target="_blank">SUN's tutorial about JConsile</a>.
                </li>
            </ul>
        </div>
    </body>
</html>

